// 类组件实现
class Modal {
  static getInstance() {
    if (!Modal.instance) {
      let modal;
      modal = document.createElement("div");
      modal.innerHTML = "我是一个全局唯一的Modal";
      modal.id = "modal";
      modal.style.display = "none";
      document.body.appendChild(modal);
      Modal.instance = modal;
    }
    return Modal.instance;
  }
}

//  实现一个弹窗
const ModalBox = Modal.getInstance();
ModalBox.style.display = "block";
const ModalBox2 = Modal.getInstance();
setTimeout(() => {
  ModalBox.style.display = "none";
}, 2000);
